package com.zly.bscloud.controller;

import com.zly.bscloud.dto.OrdersDTO;
import com.zly.bscloud.entity.Orders;
import com.zly.bscloud.service.OrdersService;
import com.zly.bscloud.utils.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author zhouxiaoyu
 * @Date 2020/3/22 11:49
 * @Version 1.0
 */
@RestController
@RequestMapping("/orders")
@Api(tags = "用户订单接口")
@CrossOrigin
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @ApiOperation(value = "进行订单预定")
    @ApiImplicitParam(name = "order" , value = "订单实体类 " , required = true , dataType = "Order")
    @PostMapping("/user-reserve")
    public Result userReserve(@RequestBody Orders orders){
        //System.out.println(orders);
        OrdersDTO ordersDTO=ordersService.userReserve(orders);
        return Result.createSuccess(ordersDTO);
    }

    @ApiOperation(value = "获得全部订单")
    @GetMapping("/get-orders")
    public Result getAllOrders(){
        List<OrdersDTO> ordersDTOList = ordersService.getAllOrders();
        return Result.createSuccess(ordersDTOList);
    }

    @GetMapping("/get-orders-one/{received}/{user_id}")
    public Result getUserOrders(@PathVariable("received") String received,
                                @PathVariable("user_id") String user_id){
        //System.out.println(received);
        //System.out.println(user_id);
        List<OrdersDTO> ordersDTOList = ordersService.getUserOrders(received,user_id);
        //System.out.println(ordersDTOList);
        return Result.createSuccess(ordersDTOList);
    }

    @GetMapping("/get-receives-one/{received}/{user_id}")
    public Result getUseReceives(@PathVariable("received") String received,
                                @PathVariable("user_id") String user_id){
        //System.out.println(received);
        //System.out.println(user_id);
        List<OrdersDTO> ordersDTOList = ordersService.getUserReceives(received,user_id);
        //System.out.println(ordersDTOList);
        return Result.createSuccess(ordersDTOList);
    }

    @ApiOperation(value = "获得订单详情")
    @GetMapping("/get-order-detail/{id}")
    public Result getOrderDetail(@PathVariable("id") String id){
        OrdersDTO ordersDTO = ordersService.getOrdersByAId(id);
        return Result.createSuccess(ordersDTO);
    }

    @ApiOperation(value = "接收订单")
    @ApiImplicitParam(name = "map" , value = "其中数据包含订单id和用户id" , required = true , dataType = "Map")
    @PutMapping("/user-reserved")
    public Result userReserved(@RequestBody Map<String,String> map){
        ordersService.userReserved(map);
        return Result.createSuccess();
    }
}
